# 斐波那契数列
def fib(n):
    if n < 2:
        return n
    else:
        return fib(n - 2) + fib(n - 1)


print(fib(8))


# 快排
def quick(qlist):
    if len(qlist) == 0:
        return qlist
    else:
        qb = qlist[0]
        qa = quick([l for l in qlist[1:] if l <= qb])
        qc = quick([m for m in qlist[1:] if m > qb])
    return qa + [qb] + qc


print(quick([43, 25, 2, 636, 14]))


# 随机插入排序
def insertQuick(qlist):
    for i in range(1, len(qlist)):
        key = qlist[i]
        j = i - 1
        while j >= 0 and key < qlist[j]:
            qlist[j + 1] = qlist[j]
            j -= 1
            qlist[j + 1] = key
    return qlist


print(insertQuick([23, 34, 25, 3, 25]))


# 99乘法表
def n_n():
    for i in range(1, 10):
        for j in range(1, i + 1):
            print(f'{j}*{i}={j * i} ', end=" ")
        print('\t')


print(n_n())


# 统计字符串中出现次数最多的字符和次数
def strMore():
    s1 = "skdjaksjJKAdjkasjffkk"
    d1 = {}
    for s in s1:
        if s not in d1:
            d1[s] = 1
        else:
            d1[s] += 1

    for k, v in d1.items():
        if v == max(d1.values()):
            print(k, v)
    return True


print(strMore())


# Switch语句
def swc():
    d1 = {
        "a": 1,
        "b": 12,
        "c": 123,
        "d": 1234,
    }
    print(d1["d"])


print(swc())


# filter()筛选功能
def f_fun(name):
    if name.startswith("刘"):
        return True


print(list(filter(f_fun, ['丰月', "狗腿", "王房", "刘翘", "岳周夜！"])))


# map()映射方法
def add(i):
    i = i ** 3
    return i


print(list(map(add, [2, 3, 4, 5])))


# 获取list索引位置
def listIndex():
    l1 = [2, 3, 4, 5]
    print(l1.index(5))


listIndex()


# 判断字符串中大写的几个，小写的几个
def str1():
    s1 = "adaDDDASDADdas"
    big = 0
    small = 0
    for s in s1:
        if s.isupper():
            big += 1
        else:
            small += 1
    print(f'大写的{big}, 小写的{small}')


str1()


# 修改元组内部元素不可修改的元素
def tp():
    t1 = (1, "下！", "上！", [33, 44, 345])
    t1[3].append([123, "气！"])
    t1[3].extend([343434])
    print(t1)


tp()


# 列表推导式
def lt():
    l1 = [i for i in range(10)]
    print(l1)


lt()


# 集合推导式
def st():
    s1 = {s for s in range(10)}
    s2 = {1, 1, 2, 2, 3}  # set集合特性，去重元素
    print(s1, s2)


st()


# 字典推导式
def dt():
    l1 = ["赵", "钱", "孙", "李"]
    d1 = {i: l1[i] for i in range(len(l1))}
    print(d1)


dt()


# 函数嵌套
def wapper(name):
    i = 1
    print(i)

    def inner(*args, **kwargs):
        nonlocal i
        i = "zkk"
        print(i)
        return i

    return inner


a = wapper(name="周抗抗")
a()
print(a())


# 迭代器
def iterb():
    l1 = [1, 2, 3, 4, 5]
    l1_iter = l1.__iter__()
    print(l1_iter.__next__())
    print(l1_iter.__next__())
    print(l1_iter.__next__())
    print(l1_iter.__next__())
    print(l1_iter.__next__())


iterb()


# 生成器
def yld():
    a = 1
    b = 2
    yield a, b
    c = 3
    yield c


print(yld().__next__())


# 装饰器
def wapper(name):
    j = 5

    def inner(*args, **kwargs):
        j = 56
        print(j)
        r1 = name(*args, **kwargs)
        print(args, kwargs)
        return r1

    return inner


@wapper
def game(username, password):
    print("gameFunc", username, password)
    return "游戏开始"


print(game(13521653526, password="admin123456"))
